package com.qiaofang.applet.service.member.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.qiaofang.applet.common.base.MongoBaseService;
import com.qiaofang.applet.common.client.weixin.WxConfig;
import com.qiaofang.applet.common.client.weixin.WxService;
import com.qiaofang.applet.common.client.weixin.model.WxProperties;
import com.qiaofang.applet.common.context.QfContextHolder;
import com.qiaofang.applet.common.exception.BusinessException;
import com.qiaofang.applet.constants.BusinessConstants;
import com.qiaofang.applet.constants.MemberOperateTypeConstants;
import com.qiaofang.applet.service.member.domain.*;
import com.qiaofang.applet.service.member.repository.EmployeeRepository;
import com.qiaofang.applet.service.member.repository.MemberOperateRepository;
import com.qiaofang.applet.service.member.repository.MemberRepository;
import com.qiaofang.applet.service.member.service.MemberExploreService;
import com.qiaofang.applet.service.member.service.dto.*;
import com.qiaofang.applet.service.member.service.mapstruct.MemberOperateMapper;
import com.qiaofang.applet.service.other.domain.Corporation;
import com.qiaofang.applet.service.other.service.CorporationService;
import com.qiaofang.applet.service.other.util.DateTypeUtil;
import com.qiaofang.applet.service.property.domain.FirsthandEstate;
import com.qiaofang.applet.service.property.domain.Property;
import com.qiaofang.applet.service.property.repository.FirsthandEstateRepository;
import com.qiaofang.applet.service.property.repository.PropertyRepository;
import com.qiaofang.applet.service.property.service.dto.VisitorResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.repository.support.PageableExecutionUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static org.springframework.data.domain.Sort.Direction.ASC;
import static org.springframework.data.domain.Sort.Direction.DESC;

/**
 * @author Zym
 */
@Slf4j
@Service
public class MemberExploreServiceImpl extends MongoBaseService<MemberOperate, String> implements MemberExploreService {
    private static RestTemplate restTemplate = new RestTemplate();

    @Autowired
    private MemberOperateRepository memberOperateRepository;

    @Autowired
    private MemberRepository memberRepository;

    @Autowired
    private FirsthandEstateRepository firsthandEstateRepository;

    @Autowired
    private PropertyRepository propertyRepository;

    @Autowired
    private MemberOperateMapper memberOperateMapper;

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private CorporationService corporationService;

    @Autowired
    private WxService wxService;

    @Autowired
    private EmployeeRepository employeeRepository;


    public MemberExploreServiceImpl(MemberOperateRepository repository) {
        super(repository);
        this.memberOperateRepository = repository;
    }

    /**
     * 添加一条浏览记录
     *
     * @param memberExploreAddDto
     * @return 主键
     */
    @Override
    public String addExploreRecord(MemberExploreAddDto memberExploreAddDto) {
        String corporationCode = QfContextHolder.getContext().getCorporationCode();
        Member member = memberRepository.findByCorporationCodeAndId(corporationCode, memberExploreAddDto.getMemberId());
        if (member == null) {
            log.info("浏览记录生成失败 memberId:{},集团code:{}", memberExploreAddDto.getMemberId(), corporationCode);
            throw new BusinessException("该用户信息不存在！");
        }
        String employeeUniqueUuidParam = member.getEmployeeUniqueUuid();
        if (StringUtils.isNotEmpty(employeeUniqueUuidParam)) {
            //排除经纪人自己看自己
            if (StringUtils.equals(employeeUniqueUuidParam, memberExploreAddDto.getEmployeeUniqueUuid())) {
                return null;
            }
            //经纪人浏览记录不计入链路
            memberExploreAddDto.setParentId(null);
        }

        //现版本前端传入操作时对应的房源归属人，所以这里不查固定展示位的经纪人
        MemberOperate memberOperate = memberOperateMapper.exploreDtoToDomain(memberExploreAddDto);
        if (StringUtils.isNotEmpty(memberOperate.getParentId())) {
            MemberOperate parentNode = memberOperateRepository.findFirstById(memberOperate.getParentId());
            memberOperate.setLinkedUuid(parentNode.getLinkedUuid());
            memberOperate.setLevel(parentNode.getLevel() + 1);
        }
        memberOperate.setCreateTime(new Date());
        memberOperate.setRead(false);
        //手动赋值给操作类型
        memberOperate.setOperateType(MemberOperateTypeConstants.EXPLORE.getValue());
        memberOperate.setCorporationCode(QfContextHolder.getContext().getCorporationCode());
        MemberOperate insert = null;
        try {
            insert = memberOperateRepository.insert(memberOperate);
        } catch (Exception e) {
            log.info("插入浏览数据失败:", e);
            throw new BusinessException(JSONObject.toJSONString(e));
        }

        //发送服务通知  过滤经纪人自己
        if (!memberExploreAddDto.getBusinessType().equals(BusinessConstants.EMPLOYEE.getCode())) {
            sentWxSubscribeMessage(memberExploreAddDto);
        }
        return insert.getId();
    }

    /**
     * 写入浏览结束时间(取当前时间)
     *
     * @param
     */
    @Override
    public void setExploreDuration(String id) {
        MemberOperate memberOperate = memberOperateRepository.findFirstById(id);
        if (memberOperate == null) {
            throw new BusinessException("浏览记录不存在或新增失败！");
        }
        memberOperate.setEndTime(new Date());
        updateById(memberOperate);
    }

    @Override
    public Page<MemberOperate> getExploreRecords(MemberOperateQueryDto queryDto, Pageable pageable) {
        Criteria criteria = Criteria.where("memberId").is(queryDto.getMemberId())
                .and("operateType").is(MemberOperateTypeConstants.EXPLORE.getValue())
                .and("corporationCode").is(QfContextHolder.getContext().getCorporationCode())
                .and("businessType").is(queryDto.getBusinessType())
                .and("cityCode").is(QfContextHolder.getContext().getCityCode());
        Aggregation aggCount = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("businessUuid")
        );
        Aggregation agg = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.sort(DESC, "createTime"),//分组前排序
                Aggregation.group("businessUuid").first("businessUuid").as("businessUuid")
                        .first("createTime").as("createTime"),
                Aggregation.sort(DESC, "createTime"),//分组后排序
                Aggregation.skip(pageable.getOffset()),
                Aggregation.limit(pageable.getPageSize())
        );

        AggregationResults result = mongoTemplate.aggregate(aggCount, "member_member_operate", MemberOperate.class);
        long count = result.getMappedResults().size();
        if (count > 0) {
            result = mongoTemplate.aggregate(agg, "member_member_operate", MemberOperate.class);
        }
        List<MemberOperate> list = result.getMappedResults();
        return PageableExecutionUtils.getPage(list, pageable, () -> count);
    }

    @Override
    public Page<MemberExploreDetailDto> listAllMemberExplore(MemberBrowseListQueryDto queryDto, Pageable pageable) {
        Criteria criteria = Criteria.where("corporationCode").is(queryDto.getCorporationCode())
                .and("operateType").is(MemberOperateTypeConstants.EXPLORE.getValue())
                .and("businessType").in(BusinessConstants.FIRSTHAND_ESTATE.getCode(),
                        BusinessConstants.SALE_PROPERTY.getCode(), BusinessConstants.RENT_PROPERTY.getCode());
        if (StringUtils.isNotBlank(queryDto.getMemberId())) {
            criteria.and("memberId").is(queryDto.getMemberId());
        }
        if (!CollectionUtils.isEmpty(queryDto.getCityCodeList())) {
            criteria.and("cityCode").in(queryDto.getCityCodeList());
        }
        if (StringUtils.isNotEmpty(queryDto.getMemberCity())) {
            criteria.and("cityName").regex(".*?" + queryDto.getMemberCity() + ".*");
        }
        // 房源最近浏览时间
        if (queryDto.getBeginDate() != null && queryDto.getEndDate() != null) {
            criteria.andOperator(Criteria.where("createTime").gte(queryDto.getBeginDate()), Criteria.where("createTime").lt(queryDto.getEndDate()));
        }
        Query query = new Query().addCriteria(criteria);
        query.with(Sort.by(Sort.Order.desc("createTime")));
        long count = mongoTemplate.count(query.with(pageable), MemberOperate.class);
        List<MemberOperate> list = new LinkedList<>();
        if (count > 0) {
            list = mongoTemplate.find(query.with(pageable), MemberOperate.class);
        }
        return PageableExecutionUtils.getPage(memberOperateMapper.domainToDetailDto(list), pageable, () -> count);
    }


    @Override
    public VisitorResponseDto getEmployeeVisitors(String employeeUniqueUuid) {

        VisitorResponseDto visitorResponseDto = new VisitorResponseDto();

        String corporationCode = QfContextHolder.getContext().getCorporationCode();
        Criteria criteria = Criteria.where("corporationCode").is(corporationCode)
                .and("businessType").ne(BusinessConstants.EMPLOYEE.getCode())
                .and("operateType").is(MemberOperateTypeConstants.EXPLORE.getValue())
                .and("employeeUniqueUuid").is(employeeUniqueUuid)
                .and("createTime").gte(DateTypeUtil.getBeginOrAfterDay(new Date(), Calendar.DAY_OF_MONTH, -30));
        //历史数据
        List<MemberOperate> list = mongoTemplate.find(new Query(criteria).with(Sort.by(Sort.Order.desc("createTime"))), MemberOperate.class);
        MemberOperate memberOperate = null;
        if (!CollectionUtils.isEmpty(list)) {
            memberOperate = list.get(0);
        }

        criteria.and("read").is(Boolean.FALSE);
        Aggregation aggCount = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("memberId", "businessType", "businessUuid")
                        .first("memberId").as("memberId")
                        .first("businessType").as("businessType")
                        .first("businessUuid").as("businessUuid")
        );
        AggregationResults result = mongoTemplate.aggregate(aggCount, "member_member_operate", MemberOperate.class);
        int count = result.getMappedResults().size();
        if (count > 0) {
            visitorResponseDto.setReadCount(count);
            visitorResponseDto.setLastDate(DateFormatUtils.format(memberOperate.getCreateTime(), "yyyy-MM-dd HH:mm"));
            visitorResponseDto.setText("有客户查看了您的房源，点击查看");
        } else {
            if (memberOperate != null) {
                visitorResponseDto.setReadCount(0);
                visitorResponseDto.setLastDate(DateFormatUtils.format(memberOperate.getCreateTime(), "yyyy-MM-dd HH:mm"));
                visitorResponseDto.setText("暂无未读访客通知，点击查看历史");
            } else {
                visitorResponseDto.setReadCount(0);
                visitorResponseDto.setLastDate("");
                visitorResponseDto.setText("暂无访客通知");
            }
        }
        return visitorResponseDto;
    }

    @Override
    public void refreshBrowseStatus(String employeeUniqueUuid) {

        String corporationCode = QfContextHolder.getContext().getCorporationCode();
        Query query = new Query();
        Criteria criteria = Criteria.where("corporationCode").is(corporationCode)
                .and("businessType").ne(BusinessConstants.EMPLOYEE.getCode())
                .and("operateType").is(MemberOperateTypeConstants.EXPLORE.getValue())
                .and("read").is(false)
                .and("employeeUniqueUuid").is(employeeUniqueUuid);

        query.addCriteria(criteria);

        Update update = new Update();
        update.set("read", Boolean.TRUE);
        update.set("updateTime", new Date());
        try {
            mongoTemplate.updateMulti(query, update, MemberOperate.class);
        } catch (Exception e) {
            log.error("清除已读访客列表状态异常：", e);
            throw new BusinessException("清除已读访客列表状态异常：" + JSONObject.toJSONString(e));
        }
    }

    @Override
    public List<CustomerManageDto> assembleCustomerParams(List<String> memberIdList, String employeeUniqueUuid) {
        if (CollectionUtils.isEmpty(memberIdList)){
            return new ArrayList<>();
        }
        //获取所有的会员信息，供后续组装参数
        List<Member> members = memberRepository.findAllByCorporationCodeAndIdIn(QfContextHolder.getContext().getCorporationCode(), memberIdList);
        if (CollectionUtils.isEmpty(members)) {
            throw new BusinessException("会员数据不存在");
        }

        Map<String, Member> memberMap = members.stream().collect(Collectors.toMap(Member::getId, a -> a, (k1, k2) -> k1));
        //获取该经纪人的所有客户备注，供后续组装参数
        Employee employee = employeeRepository.findByEmployeeUniqueUuid(employeeUniqueUuid);
        if (employee == null) {
            throw new BusinessException("经纪人不存在");
        }

        List<MemberRemark> remarkList = employee.getRemarkList();
        Map<String, String> remarkMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(remarkList)) {
            remarkMap = remarkList.stream().collect(Collectors.toMap(MemberRemark::getMemberId, MemberRemark::getRemark, (k1, k2) -> k1));
        }

        //当前经纪人
        Member my = memberRepository.findFirstByCorporationCodeAndEmployeeUniqueUuid(QfContextHolder.getContext().getCorporationCode(), employeeUniqueUuid);
        if (my == null) {
            throw new BusinessException("经纪人未注册小程序");
        }

        //获取该经纪人的关注与被关注数据
        Criteria criteriaFocus = Criteria.where("memberId").is(my.getId())
                .and("businessType").is("会员")
                .and("businessUuid").in(memberIdList);

        Criteria criteriaFocusBy = Criteria.where("memberId").in(memberIdList)
                .and("businessType").is("经纪人")
                .and("businessUuid").is(employeeUniqueUuid);

        List<MemberFocus> focusList = mongoTemplate.find(new Query(criteriaFocus), MemberFocus.class);
        List<MemberFocus> focusByList = mongoTemplate.find(new Query(criteriaFocusBy), MemberFocus.class);

        //关注会员集合
        Set<String> focusSet = new HashSet<>();
        //粉丝集合
        Set<String> focusBySet = new HashSet<>();
        if (!CollectionUtils.isEmpty(focusList)) {
            focusSet = focusList.stream().map(MemberFocus::getBusinessUuid).collect(Collectors.toSet());
        }
        if (!CollectionUtils.isEmpty(focusByList)) {
            focusBySet = focusByList.stream().map(MemberFocus::getMemberId).collect(Collectors.toSet());
        }

        Criteria criteria = Criteria.where("employeeUniqueUuid").is(employeeUniqueUuid)
                .and("memberId").in(memberIdList)
                .and("operateType").in(MemberOperateTypeConstants.EXPLORE.getValue(), MemberOperateTypeConstants.SHARE.getValue());
        Aggregation aggTotal = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.sort(DESC, "createTime"),//分组前排序
                Aggregation.group("memberId", "operateType", "businessType")
                        .count().as("count")
                        .first("memberId").as("memberId")
                        .first("operateType").as("operateType")
                        .first("businessType").as("businessType")
                        .first("createTime").as("createTime"),
                Aggregation.sort(ASC, "operateType").and(Sort.by(DESC, "createTime"))//分组后排序：最近浏览的时间在第一个元素
        );
        AggregationResults resultTotal = mongoTemplate.aggregate(aggTotal, "member_member_operate", CustomerCounterDto.class);
        List<CustomerCounterDto> totalCountList = resultTotal.getMappedResults();//总量计数器
        Map<String, List<CustomerCounterDto>> totalCountMap = counterList2Map(totalCountList);


        criteria.and("createTime").gte(getDayZero(new Date()));
        Aggregation aggToday = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("memberId", "operateType", "businessType")
                        .count().as("count")
                        .first("memberId").as("memberId")
                        .first("operateType").as("operateType")
                        .first("businessType").as("businessType")
        );
        AggregationResults resultToday = mongoTemplate.aggregate(aggToday, "member_member_operate", CustomerCounterDto.class);
        List<CustomerCounterDto> todayCountList = resultToday.getMappedResults();//今日增量计数器
        Map<String, List<CustomerCounterDto>> todayCountMap = counterList2Map(todayCountList);

        List<CustomerManageDto> customerManageDtoList = new ArrayList<>(memberIdList.size());
        for (String memberId : memberIdList) {
            String remark = remarkMap.get(memberId);
            Member member = memberMap.get(memberId);
            List<CustomerCounterDto> totalCounterList = totalCountMap.get(memberId);
            List<CustomerCounterDto> todayCounterList = todayCountMap.get(memberId);
            String visitTime = "";
            Long fyExploreCount = 0L;
            Long shopExploreCount = 0L;
            Long shareCount = 0L;
            Long todayFyExploreCount = 0L;
            Long todayShopExploreCount = 0L;
            Long todayShareCount = 0L;
            if (!CollectionUtils.isEmpty(totalCounterList)) {
                for (int i = 0; i < totalCounterList.size(); i++) {
                    CustomerCounterDto customerCounterDto = totalCounterList.get(i);
                    if (i == 0) {
                        visitTime = dateTransform(customerCounterDto.getCreateTime());
                    }
                    if (customerCounterDto.getOperateType().equals(MemberOperateTypeConstants.SHARE.getValue())) {
                        shareCount += customerCounterDto.getCount();
                    } else {
                        if (customerCounterDto.getBusinessType().equals(BusinessConstants.EMPLOYEE.getCode())) {
                            shopExploreCount += customerCounterDto.getCount();
                        } else {
                            fyExploreCount += customerCounterDto.getCount();
                        }
                    }
                }
            }
            if (!CollectionUtils.isEmpty(todayCounterList)) {
                for (int i = 0; i < todayCounterList.size(); i++) {
                    CustomerCounterDto customerCounterDto = todayCounterList.get(i);
                    if (customerCounterDto.getOperateType().equals(MemberOperateTypeConstants.SHARE.getValue())) {
                        todayShareCount += customerCounterDto.getCount();
                    } else {
                        if (customerCounterDto.getBusinessType().equals(BusinessConstants.EMPLOYEE.getCode())) {
                            todayShopExploreCount += customerCounterDto.getCount();
                        } else {
                            todayFyExploreCount += customerCounterDto.getCount();
                        }
                    }
                }
            }
            customerManageDtoList.add(CustomerManageDto.builder()
                    .memberId(memberId)
                    .employeeUniqueUuid(member.getEmployeeUniqueUuid())
                    .memberName(StringUtils.isNotEmpty(remark) ? remark : member.getName())
                    .headPortrait(member.getHeadPortrait())
                    .fansFlag(focusBySet.contains(memberId))
                    .focusFlag(focusSet.contains(memberId))
                    .visitTime(visitTime)
                    .fyExploreCount(fyExploreCount)
                    .shopExploreCount(shopExploreCount)
                    .shareCount(shareCount)
                    .todayFyExploreCount(todayFyExploreCount)
                    .todayShopExploreCount(todayShopExploreCount)
                    .todayShareCount(todayShareCount)
                    .build());
        }

        return customerManageDtoList;
    }

    private Map<String, List<CustomerCounterDto>> counterList2Map(List<CustomerCounterDto> totalCountList) {
        Map<String, List<CustomerCounterDto>> totalCountMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(totalCountList)) {
            for (CustomerCounterDto customerCounterDto : totalCountList) {
                String memberId = customerCounterDto.getMemberId();
                List<CustomerCounterDto> customerCounterDtos = totalCountMap.get(memberId);
                if (CollectionUtils.isEmpty(customerCounterDtos)) {
                    customerCounterDtos = new LinkedList<>();
                    customerCounterDtos.add(customerCounterDto);
                    totalCountMap.put(memberId, customerCounterDtos);
                } else {
                    customerCounterDtos.add(customerCounterDto);
                }
            }
        }
        return totalCountMap;
    }

    private Date getDayZero(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    private void sentWxSubscribeMessage(MemberExploreAddDto memberExploreAddDto) {

        String corporationCode = QfContextHolder.getContext().getCorporationCode();

        Corporation corporation = corporationService.getCorporationByCorporationCode(corporationCode);
        if (corporation == null) {
            throw new BusinessException("该集团不存在！");
        }

        Member employeeMember = memberRepository.findFirstByCorporationCodeAndEmployeeUniqueUuid(corporation.getCorporationCode(), memberExploreAddDto.getEmployeeUniqueUuid());

        if (employeeMember == null) {
            return;
        }
        WxProperties wxProperties = new WxProperties();
        wxProperties.setAppId(corporation.getAuthAppId());
        wxProperties.setAppSecret(corporation.getAuthAppSecret());

        JSONObject json = new JSONObject();
        json.put("touser", employeeMember.getOpenid());
        json.put("template_id", corporation.getTemplateId());
        Map<String, Map<String, String>> map = new HashMap();

        //小区名称+户型+面积
        String square = "";
        if (memberExploreAddDto.getBusinessType() == BusinessConstants.FIRSTHAND_ESTATE.getCode()) {
            FirsthandEstate firsthandEstate = firsthandEstateRepository.findFirstByEstateUniqueUuidAndCorporationCode(memberExploreAddDto.getBusinessUuid(), corporationCode);
            square = firsthandEstate.getBuildingAreaRange();
        } else {
            Property property = propertyRepository.findByCorporationCodeAndPropertyUniqueUuid(corporationCode, memberExploreAddDto.getBusinessUuid());
            square = property.getSquare().toString();
        }
        String finalSquare = "";
        if (StringUtils.isNotBlank(square)) {
            finalSquare = square + "㎡";
        }
        String finalSquare1 = finalSquare;
        String data = StringUtils.defaultString(memberExploreAddDto.getEstateName(), "")
                + " " + StringUtils.defaultString(memberExploreAddDto.getHouseType(), "")
                + " " + StringUtils.defaultString(finalSquare1, "");
        if (data.length() > 20) {
            data = data.substring(0, 16) + "...";
        }
        String finalData = data;
        map.put("thing1", new HashMap<String, String>() {{
            put("value", memberExploreAddDto.getMemberName());
        }});
        map.put("thing2", new HashMap<String, String>() {{
            put("value", finalData);
        }});
        map.put("time3", new HashMap<String, String>() {{
            put("value", DateFormatUtils.format(new Date(), "yyyy年MM月dd日 HH:mm"));
        }});
        json.put("page", "/pages/message/vistors/main");
        json.put("data", map);
        String url = String.format(WxConfig.GET_SUBSCRIBE_URI, wxService.getAccessToken(wxProperties));
        ResponseEntity<String> stringResponseEntity = null;
        try {
            stringResponseEntity = restTemplate.postForEntity(url, json, String.class);
        } catch (RestClientException e) {
            log.error("发送访客订阅消息失败：", e);
        }
        log.info("wxSubscribe:{}", stringResponseEntity.getBody());
    }


    private String dateTransform(Date date) {
        if (date == null){
            return "";
        }
        //年度判断
        String time;
        if (DateUtil.thisYear() == DateUtil.year(date)) {
            //今天
            if (DateUtil.isSameDay(new Date(), date)) {
                time = DateUtil.format(date, "HH:mm");
            } else {
                long l = DateUtil.betweenDay(date, new Date(), true);
                time = l == 1L ? "昨天" + " " + DateUtil.format(date, "HH:mm") : DateUtil.format(date, "MM/dd HH:mm");
            }
            return time;
        }
        return DateUtil.format(date, "yyyy/MM/dd");
    }
}
